/**********************************************
/ file : ifft.sc
/ Author : Jungmin Park
/ Date : 4/19/2011 
/ Specification Model of Data Storage 
***********************************************/
#include <math.h>
#include <stdio.h>
#define PI 3.141592

import "c_double_handshake";

behavior ifft(i_receiver ir, i_sender is)
{
  float x_re [16];
  float x_im [16];
  float temp1 = 0;
  float temp2 = 0;
  int i;
  int j;
  
  void main (void)
  {
    while (1) {
      for (i=0; i<16; i++) {
        ir.receive(&x_re[i], sizeof(float));
        ir.receive(&x_im[i], sizeof(float));
      }
     
      for (i=0; i < 16; i++) {
        for (j=0; j < 16 ; j++) {
          // Inverse FFT
          temp1 += (*(x_re+j)*cosf(2*PI*i*j/16)-*(x_im+j)*sinf(2*PI*i*j/16)); // Real value
          temp2 += (*(x_re+j)*sinf(2*PI*i*j/16)+*(x_im+j)*cosf(2*PI*i*j/16)); // Imaginary value
        }
        temp1 = temp1/16;
        temp2 = temp2/16;
 
        is.send(&temp1, sizeof(float));
        is.send(&temp2, sizeof(float));

        temp1 = 0;
        temp2 = 0;
      }
    }
  }
};     
